package com.amazon.ags.client.achievements;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
import com.amazon.ags.api.AmazonGamesClient;
import com.amazon.ags.api.ErrorCode;
import com.amazon.ags.api.RequestResponse;
import com.amazon.ags.api.achievements.GetAchievementResponse;
import com.amazon.ags.api.achievements.GetAchievementsResponse;
import com.amazon.ags.api.achievements.LoadIconResponse;
import com.amazon.ags.api.achievements.UpdateProgressResponse;
import com.amazon.ags.api.overlay.PopUpLocation;
import com.amazon.ags.client.AmazonGamesService;
import com.amazon.ags.client.GCResponseHandleImpl;
import com.amazon.ags.client.RequestResponseImp;
import com.amazon.ags.constants.IconSize;
import com.amazon.ags.overlay.PopUpPrefs;

public class AchievementsServiceProxy
  implements AchievementsService
{
  private static final String FEATURE_NAME = "AC";
  private static final String TAG = "AC_" + AchievementsServiceProxy.class.getSimpleName();
  private final AmazonGamesClient agClient;
  private AmazonGamesService amazonGamesService;
  private final Handler apiHandler;

  public AchievementsServiceProxy(AmazonGamesClient paramAmazonGamesClient, AmazonGamesService paramAmazonGamesService, Handler paramHandler)
  {
    this.amazonGamesService = paramAmazonGamesService;
    this.agClient = paramAmazonGamesClient;
    this.apiHandler = paramHandler;
  }

  private Bundle createRequestBundle()
  {
    return new Bundle();
  }

  private Bundle createRequestBundleWithAchievement(String paramString)
  {
    Bundle localBundle = createRequestBundle();
    localBundle.putString("ACHIEVEMENT_ID", paramString);
    return localBundle;
  }

  private Bundle createRequestBundleWithAchievementProgress(String paramString, float paramFloat)
  {
    Bundle localBundle = createRequestBundleWithAchievement(paramString);
    localBundle.putFloat("ACHIEVEMENT_UPDATE_PERCENT", paramFloat);
    localBundle.putString("POP_UP_LOCATION", PopUpPrefs.INSTANCE.getLocation().toString());
    return localBundle;
  }

  private Bundle createRequestBundleWithIcon(String paramString1, String paramString2, boolean paramBoolean)
  {
    Bundle localBundle = createRequestBundleWithAchievement(paramString1);
    localBundle.putString("ACHIEVEMENT_ICON_SIZE", paramString2);
    localBundle.putBoolean("ACHIEVEMENT_UNLOCKED", paramBoolean);
    return localBundle;
  }

  public void loadIcon(final String paramString, final IconSize paramIconSize, final boolean paramBoolean, final GCResponseHandleImpl<LoadIconResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Requested icon for " + paramString + " Asynchronously with handle.");
    final Message localMessage = Message.obtain();
    localMessage.what = 16;
    final AchievementsReplyMessengerFactory localAchievementsReplyMessengerFactory = new AchievementsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localAchievementsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(AchievementsServiceProxy.this.createRequestBundleWithIcon(paramString, paramIconSize.name(), paramBoolean));
          AchievementsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new LoadIconResponseImp(20, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }

  public void requestAchievement(final String paramString, final GCResponseHandleImpl<GetAchievementResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Requested Achievement " + paramString + " Asynchronously with handle.");
    final Message localMessage = Message.obtain();
    localMessage.what = 12;
    final AchievementsReplyMessengerFactory localAchievementsReplyMessengerFactory = new AchievementsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localAchievementsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(AchievementsServiceProxy.this.createRequestBundleWithAchievement(paramString));
          AchievementsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new GetAchievementResponseImp(20, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }

  public void requestAchievements(final GCResponseHandleImpl<GetAchievementsResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Requested Achievements Asynchronously with handle.");
    final Message localMessage = Message.obtain();
    localMessage.what = 17;
    final AchievementsReplyMessengerFactory localAchievementsReplyMessengerFactory = new AchievementsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localAchievementsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(AchievementsServiceProxy.this.createRequestBundle());
          AchievementsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new GetAchievementsResponseImp(20, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }

  public void resetAchievement(final String paramString, final GCResponseHandleImpl<RequestResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Reset Achievement called on " + paramString + " Asynchronously with handle.");
    final Message localMessage = Message.obtain();
    localMessage.what = 15;
    final AchievementsReplyMessengerFactory localAchievementsReplyMessengerFactory = new AchievementsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localAchievementsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(AchievementsServiceProxy.this.createRequestBundleWithAchievement(paramString));
          AchievementsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new RequestResponseImp(20, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }

  public void resetAchievements(final GCResponseHandleImpl<RequestResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Reset achievements called Asynchronously with handle.");
    final Message localMessage = Message.obtain();
    localMessage.what = 14;
    final AchievementsReplyMessengerFactory localAchievementsReplyMessengerFactory = new AchievementsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localAchievementsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(AchievementsServiceProxy.this.createRequestBundle());
          AchievementsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new RequestResponseImp(20, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }

  public void showAchievementsOverlay(final GCResponseHandleImpl<RequestResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Show achievements overlay called Asynchronously with handle.");
    final Message localMessage = Message.obtain();
    localMessage.what = 26;
    final AchievementsReplyMessengerFactory localAchievementsReplyMessengerFactory = new AchievementsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localAchievementsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(AchievementsServiceProxy.this.createRequestBundle());
          AchievementsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new RequestResponseImp(20, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }

  public void updateProgress(final String paramString, final float paramFloat, final GCResponseHandleImpl<UpdateProgressResponse> paramGCResponseHandleImpl)
  {
    Log.d(TAG, "Update Progress called on " + paramString + " Asynchronously with handle.");
    final Message localMessage = Message.obtain();
    localMessage.what = 13;
    final AchievementsReplyMessengerFactory localAchievementsReplyMessengerFactory = new AchievementsReplyMessengerFactory(this.agClient.getAppContext());
    this.apiHandler.post(new Runnable()
    {
      public void run()
      {
        try
        {
          localMessage.replyTo = localAchievementsReplyMessengerFactory.getReplyHandleMessenger(paramGCResponseHandleImpl);
          localMessage.setData(AchievementsServiceProxy.this.createRequestBundleWithAchievementProgress(paramString, paramFloat));
          AchievementsServiceProxy.this.amazonGamesService.sendMessage(localMessage);
          return;
        }
        catch (RemoteException localRemoteException)
        {
          paramGCResponseHandleImpl.setResponse(new UpdateProgressResponseImp(20, ErrorCode.UNRECOVERABLE));
        }
      }
    });
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.amazon.ags.client.achievements.AchievementsServiceProxy
 * JD-Core Version:    0.6.2
 */